package sfeir.authform.server.authservice;

import javax.servlet.http.HttpSession;

public class AuthServiceFactory {
    public final static int STANDARD = 0;
    public final static int GOOGLE = 1;
    
    public static AuthService getAuthService(HttpSession session) {
        if (session != null && session.getAttribute("__authService.adapter") != null) {
            return getAuthService((Integer)session.getAttribute("__authService.adapter"), session);
        }
        return getAuthService(STANDARD, session);
    }
    
    public static AuthService getAuthService(Integer adapter, HttpSession session) {
        if (session != null)
            session.setAttribute("__authService.adapter", adapter);
        switch (adapter) {
            case GOOGLE:
                return new AuthServiceGoogle();
            default:
                return new AuthServiceStandard(session);
        }
     }
    
    public static AuthService getAuthService() {
        return getAuthService(STANDARD, null);
    }
    
    public static AuthService getAuthService(Integer adapter) {
        return getAuthService(adapter, null);
    }
}
